package com.bluesmart.mia;

import com.sys.DemoApp;
import com.util.ToastUtil;

import kankan.wheel.widget.WheelView;
import kankan.wheel.widget.adapters.ArrayWheelAdapter;
import android.os.Bundle;
import android.content.Intent;
import android.graphics.Color;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class AddProfileHeightActivity extends BaseActivity implements OnClickListener{
	String[] mTime;
	String[] mVol = {"0","1","2","3","4","5","6","7","8","9"};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_add_profile_height);

		((TextView) findViewById(R.id.center)).setText(getString(R.string.height));
		((Button) findViewById(R.id.right)).setCompoundDrawablesWithIntrinsicBounds(0, 0,R.drawable.a01, 0);
		
		int count = 101;
		if(((DemoApp) getApplicationContext()).glbUnit == 1) 
		{
			count = 41;
			((TextView)findViewById(R.id.unit)).setText("inch");
		}

		mTime = new String[count];
		for(int i = 0; i < count; i++)
		{
			if(((DemoApp) getApplicationContext()).glbUnit == 1) mTime[i] = String.valueOf(i + 12);
			else mTime[i] = String.valueOf(i + 30);
		}

		WheelView number = (WheelView)findViewById(R.id.hourpicker);
        number.setViewAdapter(new ArrayWheelAdapter<String>(this, mTime,Color.parseColor("#FFFFFF")));
		
		number = (WheelView)findViewById(R.id.minuteicker);
        number.setViewAdapter(new ArrayWheelAdapter<String>(this, mVol,Color.parseColor("#FFFFFF")));
	
		findViewById(R.id.left).setOnClickListener(this);
		findViewById(R.id.right).setOnClickListener(this);
	}

	@Override
	public void onClick(View arg0) {
		if(R.id.left == arg0.getId()) finish();
		else
		{
			try
			{
				double choose = Double.valueOf(mTime[((WheelView)findViewById(R.id.hourpicker)).getCurrentItem()]);
				double height = getIntent().getExtras().getDouble("height");
				if(height > choose)
				{
					ToastUtil.showToastWithAlertPic(R.string.height_tip);
					return;
				}
			}
			catch(Exception e){}
			
			Intent intent = new Intent();String value = mTime[((WheelView)findViewById(R.id.hourpicker)).getCurrentItem()]
					+ "." + mVol[((WheelView)findViewById(R.id.minuteicker)).getCurrentItem()].charAt(0);
			if(((DemoApp) getApplicationContext()).glbUnit == 1) value += "inch";
			else value += "cm";
			intent.putExtra("value",  value);
			this.setResult(RESULT_OK, intent);
			finish();
		}
	}
}
